namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CompanyDataAccess
    {
        private WSCompanyDataAccess.WSCompanyDataAccess wDataAcess = new WSCompanyDataAccess.WSCompanyDataAccess();
        private SmartSoft.DAL.CompanyDataAccess oDataAcess = new SmartSoft.DAL.CompanyDataAccess();

        public CompanyDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public void CompanyRegister(int pi_English, string ps_Code, ref bool pb_Existed, ref bool pb_Checked, ref bool pb_ParentChecked, ref string ps_Ten_Dvcs, ref string ps_Dia_Chi, ref string ps_Ms_Thue, ref string ps_Tk_NH, ref string ps_Chu_Tk, ref string ps_Ten_NH, ref string ps_Ten_TP, ref DateTime pd_Ngay_Bd_Ht, ref DateTime pd_Ngay_Kt_Ht, ref string ps_Ma_Th)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.CompanyRegister(pi_English, ps_Code, ref pb_Existed, ref pb_Checked, ref pb_ParentChecked, ref ps_Ten_Dvcs, ref ps_Dia_Chi, ref ps_Ms_Thue, ref ps_Tk_NH, ref ps_Chu_Tk, ref ps_Ten_NH, ref ps_Ten_TP, ref pd_Ngay_Bd_Ht, ref pd_Ngay_Kt_Ht, ref ps_Ma_Th);
            }
            else
            {
                oDataAcess.CompanyRegister(pi_English, ps_Code, ref pb_Existed, ref pb_Checked, ref pb_ParentChecked, ref ps_Ten_Dvcs, ref ps_Dia_Chi, ref ps_Ms_Thue, ref ps_Tk_NH, ref ps_Chu_Tk, ref ps_Ten_NH, ref ps_Ten_TP, ref pd_Ngay_Bd_Ht, ref pd_Ngay_Kt_Ht, ref ps_Ma_Th);
            }
        }

        public DataTable GetCompanies()
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetCompanies();
            }
            else
            {
                table= oDataAcess.GetCompanies();
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetCompaniesByUser(string userName)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table = wDataAcess.GetCompaniesByUser(userName);
            }
            else
            {
                table = oDataAcess.GetCompaniesByUser(userName);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetCompanies(string ps_Code)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetCompanies(ps_Code);
            }
            else
            {
                table= oDataAcess.GetCompanies(ps_Code);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public string GetSubsidiaries(string ps_UserName)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetSubsidiaries(ps_UserName);
            }
            else
            {
                return oDataAcess.GetSubsidiaries(ps_UserName);
            }
        }

        public string GetSubsidiariesNew(string p_Ma_Dvcs)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.GetSubsidiariesNew(p_Ma_Dvcs);
            }
            else
            {
                return oDataAcess.GetSubsidiariesNew(p_Ma_Dvcs);
            }
        }

        public void SetCompany(DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.SetCompany(SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                oDataAcess.SetCompany(row);
            }
        }

        public void SetEndDate(string ps_Subsidiary, DateTime pd_EndDate)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                wDataAcess.SetEndDate(ps_Subsidiary, pd_EndDate);
            }
            else
            {
                oDataAcess.SetEndDate(ps_Subsidiary, pd_EndDate);
            }
        }
    }
}

